package org.dromara.test

import org.dromara.common.web.config.properties.CaptchaProperties
import org.junit.jupiter.api.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import java.util.concurrent.TimeUnit

/**
 * 单元测试案例
 *
 * @author LikeYouDo
 */
@SpringBootTest // 此注解只能在 springboot 主包下使用 需包含 main 方法与 yml 配置文件
@DisplayName("单元测试案例")
class DemoUnitTest {

    @Autowired
    private val captchaProperties: CaptchaProperties? = null

    @DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
    @Test
    fun testTest() {
        println(captchaProperties)
    }

    @Disabled
    @DisplayName("测试 @Disabled 注解")
    @Test
    fun testDisabled() {
        println(captchaProperties)
    }

    @Timeout(value = 2L, unit = TimeUnit.SECONDS)
    @DisplayName("测试 @Timeout 注解")
    @Test
    @Throws(InterruptedException::class)
    fun testTimeout() {
        Thread.sleep(3000)
        println(captchaProperties)
    }


    @DisplayName("测试 @RepeatedTest 注解")
    @RepeatedTest(3)
    fun testRepeatedTest() {
        println(666)
    }

    @BeforeEach
    fun testBeforeEach() {
        println("@BeforeEach ==================")
    }

    @AfterEach
    fun testAfterEach() {
        println("@AfterEach ==================")
    }

    companion object {
        @JvmStatic
        @BeforeAll
        fun testBeforeAll() {
            println("@BeforeAll ==================")
        }

        @JvmStatic
        @AfterAll
        fun testAfterAll() {
            println("@AfterAll ==================")
        }
    }
}
